package com.zretc.support.dao;
import com.zretc.support.entity.Online;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.io.Serializable;
import java.util.Date;

public interface OnlineDao extends JpaRepository<Online,Integer>, JpaSpecificationExecutor<Online>,
        CrudRepository<Online,Integer>, Serializable {

    //模糊查询
    @Query("select o from Online o where o.onlineMessage like %?1% and ( o.sender.userId=?2 and o.receiver.userId=?3 ) or ( o.sender.userId=?3 and o.receiver.userId=?2 ) order by o.onlineDate")
    Page<Online> selectByPage(String keywords, String senderId, String receiverId, Pageable pageable);

    //时间段查询
    @Query("select o from Online o where ( o.onlineDate between ?1 and ?2 ) and ( o.sender.userId=?3 and o.receiver.userId=?4 ) or ( o.sender.userId=?4 and o.receiver.userId=?3 ) order by o.onlineDate")//对应第1个参数
    Page<Online> selectByDate(Date time1, Date time2, String senderId, String receiverId, Pageable pageable);
}
